Conversation
87e143e to
3a1a4fa
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5 +/- ##
============================================
+ Coverage 99.48% 99.53% +0.05%
- Complexity 166 191 +25
============================================
Files 24 26 +2
Lines 388 430 +42
============================================
+ Hits 386 428 +42
Misses 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1acc047 to
5602ca7
Compare
5602ca7 to
acab555
Compare
There was a problem hiding this comment.
Pull request overview
Adds new credit-card-specific formatters to the library, including a standard formatter and a “secure” masking variant, along with documentation and unit tests.
Changes:
- Introduces
CreditCardFormatterandSecureCreditCardFormatterimplementations. - Adds PHPUnit unit test coverage for both formatters across multiple card patterns and edge cases.
- Adds new formatter documentation pages and updates the README formatter list; extends builder/chain mixins with credit-card methods.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/CreditCardFormatter.php |
New formatter that cleans input and formats card numbers using patterns (incl. Amex/Diners/19-digit). |
src/SecureCreditCardFormatter.php |
New formatter that composes CreditCardFormatter + MaskFormatter to hide sensitive digits. |
src/Mixin/Builder.php |
Adds builder mixin methods for credit card formatters (currently contains a naming mismatch). |
src/Mixin/Chain.php |
Adds chain mixin methods for credit card formatters (currently contains a naming mismatch). |
tests/Unit/CreditCardFormatterTest.php |
New unit tests validating CreditCardFormatter behavior. |
tests/Unit/SecureCreditCardFormatterTest.php |
New unit tests validating masking and custom mask character behavior. |
docs/CreditCardFormatter.md |
New documentation page for CreditCardFormatter. |
docs/SecureCreditCardFormatter.md |
New documentation page for SecureCreditCardFormatter (contains wording mismatch). |
README.md |
Updates formatter list to include the new credit card formatters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Test method naming here uses should..., while the rest of the unit test suite consistently uses the itShould... convention (e.g. tests/Unit/AreaFormatterTest.php). Consider renaming these test methods to match the established convention for consistency.
src/Mixin/Builder.php
Outdated
There was a problem hiding this comment.
secretCreditCard() will not work with FormatterBuilder::__call() naming convention (it reflects ucfirst($name) . 'Formatter'), so it will try to instantiate Respect\StringFormatter\SecretCreditCardFormatter, which does not exist (the class added is SecureCreditCardFormatter). Rename this method to secureCreditCard() (preferred to match the class/docs) or add a SecretCreditCardFormatter alias/wrapper class so the builder/modifier pipeline can construct the formatter.
| public static function secretCreditCard(string $maskChar = '*'): FormatterBuilder; | |
| public static function secureCreditCard(string $maskChar = '*'): FormatterBuilder; |
acab555 to
04ec360
Compare
The new CreditcardFormatter automatically detects major credit card types (Visa, MasterCard, Amex, Discover, JCB) based on card prefix and length, applying the appropriate formatting pattern. This formatter is essential for payment processing applications that need to display credit card numbers in a consistent, readable format while supporting different card types with their specific formatting requirements (e.g., Amex uses 4-6-5 format while others use 4-4-4-4). Input is automatically cleaned by removing non-digit characters, making it flexible for real-world usage where cards may have spaces, dashes, or other separators. Includes comprehensive tests covering all major card types, invalid cards, custom patterns, input cleaning, and edge cases. Assisted-by: OpenCode (GLM-4.7)
Composes CreditCardFormatter and MaskFormatter to display credit card numbers with only the first and last digit groups visible. Automatically detects card type and applies the appropriate mask range for each format. Assisted-By: Claude Code (Claude Opus 4.6)
04ec360 to
315169d
Compare
No description provided.